//Abort(Math.atan2(1,-10)*(180/Math.PI));
var cx=103, cy=144;
var rx=200, ry=200, ang=0;
var doit = true;
var font = LoadFont("FF6font.rfn");
var White = CreateColor(255,255,255,255);
var cos=Math.cos, sin=Math.sin, invt=Math.atan2, sqrt=Math.sqrt, pow=Math.pow;
var tehROTmod = 1;

//Abort(sqrt( pow(rx-(cx-16),2) + pow(ry-(cy-8),2) ));

function game()
{
	SetUpdateScript("stuff_init();");
	MapEngine('Wizhousef1.rmp', 45);
}

function stuff_init()
{
	couch1 = GetTileImage(50);
	couch2 = GetTileImage(49);
	couch3 = GetTileImage(48);
	couch4 = GetTileImage(47);
	couch5 = GetTileImage(46);
	couch6 = GetTileImage(45);
	SetUpdateScript("otherjunk();");
	SetLayerRenderer(2,"megathings();");
}

function megathings()
{	
	var sx = MapToScreenX(1, cx);
	var sy = MapToScreenY(1, cy);
if (doit)
{	

	/* bottom-right rotation */
	if (tehROTmod==1)
	{
	couch1.rotateBlit(sx+46.6*cos(rad(ang+180-31.0))-8,	sy-46.6*sin(rad(ang+180-31.0))-8,	rad(-ang));
	couch4.rotateBlit(sx+40.8*cos(rad(ang+180-11.3))-8,	sy-40.8*sin(rad(ang+180-11.3))-8,	rad(-ang));
	
	couch2.rotateBlit(sx+33.9*cos(rad(ang+180-45))-8,	sy-33.9*sin(rad(ang+180-45))-8,	rad(-ang));
	couch5.rotateBlit(sx+25.3*cos(rad(ang+180-18.4))-8,	sy-25.3*sin(rad(ang+180-18.4))-8,	rad(-ang));
	
	couch3.rotateBlit(sx+25.3*cos(rad(ang+180-71.6))-8,	sy-25.3*sin(rad(ang+180-71.6))-8,	rad(-ang));
	couch6.rotateBlit(sx+11.3*cos(rad(ang+180-45))-8,	sy-11.3*sin(rad(ang+180-45))-8,	rad(-ang));
	}
	
	// bottom-left rotation //
	else if (tehROTmod==2)
	{
	couch1.rotateBlit(xmod()+sx+25.3*cos(rad(ang+71.6))-8,	sy-25.3*sin(rad(ang+71.6))-8,	rad(-ang));
	couch4.rotateBlit(xmod()+sx+11.3*cos(rad(ang+45))-8,	sy-11.3*sin(rad(ang+45))-8,	rad(-ang));
		
	couch2.rotateBlit(xmod()+sx+33.9*cos(rad(ang+45))-8,	sy-33.9*sin(rad(ang+45))-8,	rad(-ang));
	couch5.rotateBlit(xmod()+sx+25.3*cos(rad(ang+18.4))-8,	sy-25.3*sin(rad(ang+18.4))-8,	rad(-ang));
	
	couch3.rotateBlit(xmod()+sx+46.6*cos(rad(ang+31.0))-8,	sy-46.6*sin(rad(ang+31.0))-8,	rad(-ang));
	couch6.rotateBlit(xmod()+sx+40.8*cos(rad(ang+11.3))-8,	sy-40.8*sin(rad(ang+11.3))-8,	rad(-ang));
	}


}	
	font.drawText(22,15, ang);
	font.drawText(22,25, cx+" : "+cy);
	font.drawText(22,35, rx+" : "+ry);
	Point(sx, sy, White);
	Point(MapToScreenX(1,rx), MapToScreenY(1,cy), White);
	font.drawText(300,200, tehROTmod);
}

function rolr()
{
	if (tehROTmod==1) return 0;
	else if (tehROTmod==2) return 180;
	else return 0;
}

function xmod()
{
	return -48*cos(rad(ang));
}


function otherjunk()
{
	if (IsKeyPressed(KEY_T)) doit = !doit;
	if (IsKeyPressed(KEY_UP)) cy--;
	if (IsKeyPressed(KEY_LEFT)) cx--;
	if (IsKeyPressed(KEY_RIGHT)) cx++;
	if (IsKeyPressed(KEY_DOWN)) cy++;
	if (IsKeyPressed(KEY_PAGEUP)) ang++;
	if (IsKeyPressed(KEY_PAGEDOWN)) ang--;
	//SetPersonX(wedge.name, cx+30*cos(rad(ang+180))); SetPersonY(wedge.name, cy-30*sin(rad(ang+180))+8);
	//SetPersonX(vicks.name, cx+30); SetPersonY(vicks.name, cy+8);
	SetCameraX(cx); SetCameraY(cy);
	if (IsKeyPressed(KEY_A)){ ChangeMap("Albrook_entless_new.rmp"); SetLayerRenderer(2,"megathings();");}
	if (IsKeyPressed(KEY_W)){ ChangeMap("Wizhousef1.rmp"); SetLayerRenderer(2,"megathings();");}
	if (IsKeyPressed(KEY_U)) { if (tehROTmod==1) tehROTmod = 2; else if (tehROTmod==2) tehROTmod = 1; }
}

function rad(ical)
{
	return ical*Math.PI/180;
}






/*			//center-based rotation
	couch1.rotateBlit(sx +17.9*cos(rad(ang+180-26.565))-8, sy-17.9*sin(rad(ang+180-26.565))-8, rad(-ang));
	couch4.rotateBlit(sx+17.9*cos(rad(ang+180+26.565))-8, sy-17.9*sin(rad(ang+180+26.565))-8, rad(-ang));
	
	couch2.rotateBlit(sx+8*cos(rad(ang+90))-8,   sy-8*sin(rad(ang+90))-8,  rad(-ang));
	couch5.rotateBlit(sx+8*cos(rad(ang+270))-8, sy-8*sin(rad(ang+270))-8, rad(-ang));
	
	couch3.rotateBlit(sx+17.9*cos(rad(ang+26.565))-8,       sy-17.9*sin(rad(ang+26.565))-8,        rad(-ang));
	couch6.rotateBlit(sx+17.9*cos(rad(ang+360-26.565))-8, sy-17.9*sin(rad(ang+360-26.565))-8, rad(-ang));
*/






function npcrap(eman)
{
	this.name = eman;
	this.step = 0;
	this.mark = 0;
	this.face = true;
	this.toobusy = false;
	this.shop = false;
	this.diamark = 1;
	this.incremental = false;
	this.talkrand = false;
	this.firstonce = false;
	this.notperson = false;
	this.dirs = new Array('w');
}

function retard(eman,rss,sheeit)
{
	this.name = eman;
	this.step = 0;
	this.mark = 0;
	this.rss = rss;
	this.dirs = new Array('w');
	CreatePerson(eman, rss, sheeit);
}

function Albrook_init()
{
}

function walkgay(guy, dir)
{
	
	switch (dir)
	{		
		case ("l"):
		{
			QueuePersonCommand(guy.name, COMMAND_MOVE_WEST, false);
			if (guy.mark >= 16)
			{
				guy.step++;
				guy.mark = 0;				
			}
			else guy.mark++;
			break;
		}
	
		case ("r"):
		{
			QueuePersonCommand(guy.name, COMMAND_MOVE_EAST, false);
			if (guy.mark >= 16)
			{
				guy.step++;
				guy.mark = 0;
			}
			else guy.mark++;
			break;
		}
		case ("u"):
		{
			QueuePersonCommand(guy.name, COMMAND_MOVE_NORTH, false);
			if (guy.mark >= 16)
			{
				guy.step++;
				guy.mark = 0;
			}
			else guy.mark++;
			break;
		}
		case ("d"):
		{
			QueuePersonCommand(guy.name, COMMAND_MOVE_SOUTH, false);
			if (guy.mark >= 16)
			{
				guy.step++;
				guy.mark = 0;
			}
			else guy.mark++;
			break;
		}
		case ("w"):
		{
			QueuePersonCommand(guy.name, COMMAND_WAIT, false);
			if (guy.mark >= 16)
			{
				guy.step++;
				guy.mark = 0;
			}
			else guy.mark++;
			break;
		}
		case ("fu"):
		{
			QueuePersonCommand(guy.name, COMMAND_FACE_NORTH, false);
			guy.step++;
			break;
		}
		case ("fl"):
		{
			QueuePersonCommand(guy.name, COMMAND_FACE_WEST, false);
			guy.step++;
			break;
		}
		case ("fr"):
		{
			QueuePersonCommand(guy.name, COMMAND_FACE_EAST, false);
			guy.step++;
			break;
		}
		case ("fd"):
		{
			QueuePersonCommand(guy.name, COMMAND_FACE_SOUTH, false);
			guy.step++;
			break;
		}
		case ("ul"):
		{
			QueuePersonCommand(guy.name, COMMAND_MOVE_NORTH, false);
			QueuePersonCommand(guy.name, COMMAND_MOVE_WEST, false);
			if (guy.mark >= 16)
			{
				guy.step++;
				guy.mark = 0;
			}
			else guy.mark++;
			break;
		}
		case ("ur"):
		{
			QueuePersonCommand(guy.name, COMMAND_MOVE_NORTH, false);
			QueuePersonCommand(guy.name, COMMAND_MOVE_EAST, false);
			if (guy.mark >= 16)
			{
				guy.step++;
				guy.mark = 0;
			}
			else guy.mark++;
			break;
		}
		case ("dl"):
		{
			QueuePersonCommand(guy.name, COMMAND_MOVE_SOUTH, false);
			QueuePersonCommand(guy.name, COMMAND_MOVE_WEST, false);
			if (guy.mark >= 16)
			{
				guy.step++;
				guy.mark = 0;
			}
			else guy.mark++;
			break;
		}
		case ("dr"):
		{
			QueuePersonCommand(guy.name, COMMAND_MOVE_SOUTH, false);
			QueuePersonCommand(guy.name, COMMAND_MOVE_EAST, false);
			if (guy.mark >= 16)
			{
				guy.step++;
				guy.mark = 0;
			}
			else guy.mark++;
			break;
		}
		default:
		{
			QueuePersonScript(guy.name, dir, false);
			guy.step++;
			guy.mark = 0;
			break;
		}
		}	//end switch
}